package com.example.transaction_service_b.service.impl;

import com.example.transaction_service_b.service.EventProcessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.core.annotation.Order;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/5/18.
 */
@Service
public class EventProcessServiceImpl implements EventProcessService {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public List<Map<String, Object>> selectDataByNew() {
        return jdbcTemplate.queryForList("SELECT * FROM transaction_eventProcess where status = 'new'");
    }

    @Override
    public boolean insertData(Map<String, Object> paramMap) {
        return jdbcTemplate.update("INSERT INTO transaction_eventProcess(status,payload,eventType) VALUES (?,?,?)",paramMap.get("status"),paramMap.get("payload"),paramMap.get("eventType"))>0?true:false;
    }

    @Override
    @Transactional
    public int updateDataByStatus() {
        return jdbcTemplate.update("UPDATE transaction_eventProcess SET status = 'published' WHERE status = 'new'");
    }
}
